home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / What's New? / Tool Chest / Memory Monitor / MemoryMonitor.vulib < prev   
Encoding:
Text File  |  1993-08-13  |  13.4 KB  |  403 lines  |  [TEXT/MPS ]

  1. #######################################################################################
  2. #    InitMemoryMonitor( OnTarget := false )
  3. #
  4. #    Prepares Memory Monitor as an external tool.
  5. #
  6. # Input:
  7. #
  8. #    OnTarget
  9. #        Pass in true if Memory Monitor is to run on a target, false for the Host.
  10. #        By default Memory Monitor runs on the Host
  11. #    
  12. #######################################################################################
  13. Task InitMemoryMonitor( OnTarget := false )
  14. Begin
  15.     x := MemoryMonitor( "Initialize", OnTarget );
  16.     Script_Error := ScriptError();
  17.     return { x[1], x[2], x[3], Script_Error };
  18. end;
  19.  
  20.  
  21. #######################################################################################
  22. #    QuitMemoryMonitor()
  23. #
  24. #    Causes Memory Monitor application to 'Quit'.
  25. #
  26. #######################################################################################
  27. Task QuitMemoryMonitor()
  28. Begin
  29.     x := MemoryMonitor( "Quit" );
  30.     Script_Error := ScriptError();
  31.     return { x[1], x[2], x[3], Script_Error };
  32. end;
  33.  
  34.  
  35. #######################################################################################
  36. #    GetAllProcesses( pCallAsync := false )
  37. #
  38. #    Returns a list of all processes which are currently running.
  39. #
  40. # Input:
  41. #
  42. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  43. #
  44. # Output:
  45. #
  46. #    The return value is a list of ProcessRecord elements: { ProcRec, ProcRec, ... }
  47. #    Each ProcessRecord element is a list containing the following elements
  48. #    
  49. # Index    Data Type    Label        Significance
  50. # ----- ---------   -----       ------------
  51. #    1    string        Name        The name of the process        
  52. #    2    string        Type        The 4 letter type code    
  53. #    3    string        Signature    The 4 letter signature code        
  54. #    4    string        Location    Decimal digits of address of the heap zone
  55. #    5    string        Size        Decimal digits of heap zone size in bytes
  56. #    6    string        Free        Decimal digits of Free Memory in bytes
  57. #    
  58. #######################################################################################
  59. Task GetAllProcesses( pCallAsync := false )
  60. Begin
  61.     x := MemoryMonitor( "GetAllProcesses" ) Async:pCallAsync;
  62.     Script_Error := ScriptError();
  63.     return { x[1], x[2], x[3], Script_Error };
  64. end;
  65.  
  66.  
  67. #######################################################################################
  68. #    GetProcessInfo( ProcName, pCallAsync := false )
  69. #
  70. #    Returns Process Manager information for the process specified
  71. #    by the ProcName paramter
  72. #
  73. # Input:
  74. #
  75. #    ProcName    string        The name of the process of interest
  76. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  77. #
  78. # Output:
  79. #
  80. #    return value is a ProcessRecord containing the following elements
  81. #    
  82. # Index    Data Type    Label        Significance
  83. # ----- ---------   -----       ------------
  84. #    1    string        Name        The name of the process        
  85. #    2    string        Type        The 4 letter type code    
  86. #    3    string        Signature    The 4 letter signature code        
  87. #    4    string        Location    Decimal digits of address of the heap zone
  88. #    5    string        Size        Decimal digits of heap zone size in bytes
  89. #    6    string        Free        Decimal digits of Free Memory in bytes
  90. #    
  91. #######################################################################################
  92. Task GetProcessInfo( ProcName, pCallAsync := false )
  93. Begin
  94.     x := MemoryMonitor( "GetProcessInfo", ProcName ) Async:pCallAsync;
  95.     Script_Error := ScriptError();
  96.     return { x[1], x[2], x[3], Script_Error };
  97. end;
  98.  
  99.  
  100. #######################################################################################
  101. #    GetZoneMap(  ZoneSelector, pCallAsync := false )
  102. #
  103. #    Returns a list containing location and size info for the specified zone 
  104. #    and all zones nested within the specified zone.
  105. #
  106. # Input:
  107. #
  108. #    ZoneSelector        Determines which heap zone, may be of two forms:
  109. #
  110. #    Form 1:    string        
  111. #        The process/zone name        
  112. #            
  113. #        Example 'Finder'    - the Finder's heap zone
  114. #            
  115. #    Form 2: { string [[,integer] ...] }    
  116. #        Element 1 determines the root heap zone 
  117. #        Each following index specifies which nested heap zone
  118. #
  119. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  120. #
  121. #        There are two names which can be used in the place of a prcess name
  122. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  123. #        to the two root heap zones.
  124. #
  125. #        Example { 'System', 1 } - The first nested heap within the System heap.
  126. #
  127. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  128. #
  129. # Output:
  130. #
  131. #    The return value is a list of ZoneRecord elements: { ZoneLoc, ZoneLoc, ... }
  132. #    Note the fourth element is a list which may contain more ZoneRecord elements.
  133. #    Since heap zones can be nested, ZoneRecords can also be nested.
  134. #    
  135. # Index    Data Type    Label            Significance
  136. # ----- ---------   -----           ------------
  137. #    1    string        StartAddress    Decimal digits of address where heap zone begins
  138. #    2    string        EndAddress        Decimal digits of address where heap zone ends
  139. #    3    string        Size            Decimal digits of size of the heap zone in bytes
  140. #    4    list        NestedZones        List of all nested heap zones
  141. #    
  142. #######################################################################################
  143. Task GetZoneMap(  ZoneSelector := "", pCallAsync := false )
  144. Begin
  145.     x := MemoryMonitor( "GetZoneMap", ZoneSelector ) Async:pCallAsync;
  146.     Script_Error := ScriptError();
  147.     return { x[1], x[2], x[3], Script_Error };
  148. end;
  149.  
  150.  
  151. #######################################################################################
  152. #    GetZoneTotals( ZoneSelector, pCallAsync := false )
  153. #
  154. #    Returns a summary of how memory is allocated within a specified heap zone.
  155. #    The total bytes and number of blocks is returned for each of the following
  156. #    catagories : 
  157. #        Free,  
  158. #        Relocatable,  
  159. #        Non-Relocatable,   
  160. #        Non-Relocatable/Locked, 
  161. #        Non-Relocatable/Not Locked & Purgable
  162. #    
  163. #    This is similar to Macsbug's HT (heap totals) command
  164. #
  165. # Input:
  166. #
  167. #    ZoneSelector        Determines which heap zone, may be of two forms:
  168. #
  169. #    Form 1:    string        
  170. #        The process/zone name        
  171. #            
  172. #        Example 'Finder'    - the Finder's heap zone
  173. #            
  174. #    Form 2: { string [[,integer] ...] }    
  175. #        Element 1 determines the root heap zone 
  176. #        Each following index specifies which nested heap zone
  177. #
  178. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  179. #
  180. #        There are two names which can be used in the place of a prcess name
  181. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  182. #        to the two root heap zones.
  183. #
  184. #        Example { 'System', 1 } - The first nested heap within the System heap.
  185. #
  186. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  187. #
  188. # Output:
  189. #
  190. #    return value is a list of one element for each catagory of block allocation type
  191. #    Each element is itself a list containing two values, number of blocks and total bytes 
  192. #    'number of blocks' is an integer value, and 'total bytes' is a string of decimal digits
  193. #    
  194. # Index    Data Type    Label        Significance
  195. # ----- ---------   -----       ------------
  196. #    1    list        Free                                    { number of blocks, total bytes }
  197. #    2    list        Relocatable                                { number of blocks, total bytes }
  198. #    3    list        Non-Relocatable                            { number of blocks, total bytes }
  199. #    4    list        Non-Relocatable/Locked                    { number of blocks, total bytes }
  200. #    5    list        Non-Relocatable/Not Locked & Purgable    { number of blocks, total bytes }
  201. #    6    list        Total                                    { number of blocks, total bytes }
  202. #    
  203. #######################################################################################
  204. Task GetZoneTotals( ZoneSelector, pCallAsync := false )
  205. Begin
  206.     x := MemoryMonitor( "GetZoneTotals", ZoneSelector ) Async:pCallAsync;
  207.     Script_Error := ScriptError();
  208.     return { x[1], x[2], x[3], Script_Error };
  209. end;
  210.  
  211.  
  212. #######################################################################################
  213. #    CheckZone( ZoneSelector, pCallAsync := false )
  214. #
  215. #    Checks the Memory Manager data structures within the specified heap zone
  216. #    Returns true if no inconsistencies are found.
  217. #    
  218. #    This is similar to Macsbug's HC (heap check) command
  219. #
  220. # Input:
  221. #
  222. #    ZoneSelector        Determines which heap zone, may be of two forms:
  223. #
  224. #    Form 1:    string        
  225. #        The process/zone name        
  226. #            
  227. #        Example 'Finder'    - the Finder's heap zone
  228. #            
  229. #    Form 2: { string [[,integer] ...] }    
  230. #        Element 1 determines the root heap zone 
  231. #        Each following index specifies which nested heap zone
  232. #
  233. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  234. #
  235. #        There are two names which can be used in the place of a prcess name
  236. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  237. #        to the two root heap zones.
  238. #
  239. #        Example { 'System', 1 } - The first nested heap within the System heap.
  240. #
  241. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  242. #
  243. # Output:
  244. #
  245. #    The return value is a symbol : either true or false
  246. #    
  247. #######################################################################################
  248. Task CheckZone( ZoneSelector, pCallAsync := false )
  249. Begin
  250.     x := MemoryMonitor( "CheckZone", ZoneSelector ) Async:pCallAsync;
  251.     Script_Error := ScriptError();
  252.     return { x[1], x[2], x[3], Script_Error };
  253. end;
  254.  
  255.  
  256.  
  257. #######################################################################################
  258. #    GetAboutThisMacintosh( pCallAsync := false )
  259. #
  260. #    Returns information contained in the "About this Macintosh" box.
  261. #    
  262. # Input:
  263. #
  264. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  265. #
  266. # Output:
  267. #
  268. #    The return value is a list of items from Finder's About Box ( "About This Macintosh" ).
  269. #    Each element of the list is as follows:
  270. #
  271. # Index    Data Type    Label            Significance
  272. # ----- ---------   -----              ------------
  273. #    1    string        PhysicalRAM        Decimal digits of 'Built-in Memory'
  274. #    2    string        LogicalRAM        Decimal digits of 'Total Memory'
  275. #    3    string        LargestBlock    Decimal digits of 'Largest unused block'
  276. #    4    list        Processes        List of info for each process
  277. #    
  278. #    The 'Processes' element is a list containing one of the following records 
  279. #    for each process.
  280. #
  281. # Index    Data Type    Label            Significance
  282. # ----- ---------   -----              ------------
  283. #    1    string        Name            Process name
  284. #    2    string        LargestBlock    Decimal digits of process size in bytes
  285. #
  286. #######################################################################################
  287. Task GetAboutThisMacintosh( pCallAsync := false )
  288. Begin
  289.     x := MemoryMonitor( "GetAboutThisMacintosh" ) Async:pCallAsync;
  290.     Script_Error := ScriptError();
  291.     return { x[1], x[2], x[3], Script_Error };
  292. end;
  293.  
  294. #######################################################################################
  295. #    ReadBytes( pAddress, pCount, pCallAsync := false )
  296. #
  297. #    Returns a list of contiguous bytes from memory
  298. #    
  299. # Input:
  300. #
  301. #    pAddress        list        The location of the first byte to read.
  302. #                                The list must contain the High & Low words of the address
  303. #
  304. #    pCount            integer        The number of bytes to read
  305. #
  306. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  307. #
  308. # Output:
  309. #
  310. #    The return value is a list of integers.
  311. #    Each one is equal to the value of the byte read from memory.
  312. #
  313. #######################################################################################
  314. Task ReadBytes( pAddress, pCount, pCallAsync := false )
  315. Begin
  316.     x := MemoryMonitor( "ReadBytes", pAddress, pCount ) Async:pCallAsync;
  317.     Script_Error := ScriptError();
  318.     return { x[1], x[2], x[3], Script_Error };
  319. end;
  320.  
  321. #######################################################################################
  322. #    MacsbugCmd( Commands, Label := "Memory Moniotr", RemainInMacsBug := false, pCallAsync := false )
  323. #
  324. #    Executes a Macsbug command, via Macsbug command line
  325. #    
  326. # Input:
  327. #
  328. #    Commands        string        One or more Macsbug commands, separated by semi-colons.
  329. #
  330. #    Label            string        Optional label which is desplayed in Macsbug,
  331. #                                prior to command line execution
  332. #
  333. #    RemainInMacsBug    string        if false, a "Go" command is appended to the command line
  334. #                                otherwise, no "Go" command is appeded. This makes it possible
  335. #                                to remain in Macsbug ( for what ever reason )
  336. #
  337. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  338. #
  339. # Output:
  340. #
  341. #    The return value is the 'true' symbol if successful, otherwise 'undefined'
  342. #
  343. #######################################################################################
  344. Task MacsbugCmd( CommandLine, Label := "Memory Monitor", RemainInMacsBug := false, pCallAsync := false )
  345. Begin
  346.         ###    Append a "Go" command so we won't stay in Macsbug
  347.     if RemainInMacsBug
  348.     begin
  349.         CommandLine := "{Label}; {CommandLine}";
  350.     end;
  351.     else
  352.     begin
  353.         CommandLine := "{Label}; {CommandLine} ;g";
  354.     end;
  355.     
  356.     x := MemoryMonitor( "MacsbugCmd", CommandLine ) Async:pCallAsync;
  357.     Script_Error := ScriptError();
  358.     return { x[1], x[2], x[3], Script_Error };
  359. end;
  360.  
  361.  
  362. #######################################################################################
  363. #    MemoryMonitor Tool Declaration
  364. #
  365. #    Defines the V.U. scripting interface to Memory Monitor
  366. #
  367. Tool MemoryMonitor s:'MMTL'
  368. begin
  369.         #####################################################
  370.         ### Services specific to Memory Monitor:
  371.     
  372.         ### Process Manager
  373.     Service "GetAllProcesses"( )                 return 'list';
  374.     Service "GetProcessInfo"( )                 return 'list';
  375.  
  376.         ### Heap Zone
  377.     Service "GetZoneMap"( 'undefined' )            return 'list';
  378.     Service "GetZoneTotals"( 'undefined' )        return 'list';
  379.     Service "CheckZone"( 'undefined' )            return 'symbol';
  380.  
  381.         ### Finder's About Box
  382.     Service "GetAboutThisMacintosh"( )            return 'list';
  383.  
  384.         ### Reading Memory
  385.     Service "ReadBytes"( 'list', 'integer' )    return 'list';
  386.  
  387.         ### Macsbug Command
  388.     Service "MacsbugCmd"( 'string' )            return 'symbol';
  389.     
  390.         #####################################################
  391.         ### Services common to all Virtual User external tools:
  392.     
  393.     Service "Initialize"        ( 'undefined' );
  394.     Service "Cancel"            ( 'string' );
  395.     Service "Poll"                ( 'string' )     return 'string';
  396.     Service "ServiceSupported"    ( 'string' )     return 'undefined';
  397.     Service "GetToolServices"    ()                 return 'list';
  398.     Service "GetToolVersion"    ()                 return 'list';
  399.     Service "Quit"();
  400.  
  401. end;
  402.  
  403.